package com.example.moshudriver.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.BeeFramework.Utils.TimeUtil;
import com.BeeFramework.Utils.Utils;
import com.BeeFramework.adapter.BeeBaseAdapter;
import com.sgr.dykdriver.R;
import com.example.moshudriver.protocol.ORDER_INFO;
import com.example.moshudriver.tools.LocationManager;
import com.example.moshudriver.utils.StringUtils;
import com.nostra13.universalimageloader.core.ImageLoader;

public class E0_NearOrderListAdapter extends BeeBaseAdapter {
	protected ImageLoader mImageLoader = ImageLoader.getInstance();

	public E0_NearOrderListAdapter(Context c, ArrayList orderList) {
		super(c, orderList);
	}

	public class E0_OrderCellHolder extends BeeCellHolder {
		private TextView name_start;
		private TextView name_end;
		TextView serviceStatus;
		TextView time;
		TextView price;
	}

	@Override
	protected BeeCellHolder createCellHolder(View cellView) {
		E0_OrderCellHolder holder = new E0_OrderCellHolder();

		holder.name_start = (TextView) cellView
				.findViewById(R.id.tv_name_start);
		holder.name_end = (TextView) cellView.findViewById(R.id.tv_name_end);
		holder.serviceStatus = (TextView) cellView
				.findViewById(R.id.e0_service_location);
		holder.time = (TextView) cellView.findViewById(R.id.e0_create_time);
		holder.price = (TextView) cellView.findViewById(R.id.e0_price);
		return holder;
	}

	// 绑定订单数据
	@Override
	protected View bindData(int position, View cellView, ViewGroup parent,
			BeeCellHolder h) {
		ORDER_INFO order_info = (ORDER_INFO) dataList.get(position);
		E0_OrderCellHolder holder = (E0_OrderCellHolder) h;
		if (order_info != null) {
			holder.name_start.setText(order_info.location.name.substring(
					order_info.location.name.indexOf("市") + 1,
					order_info.location.name.length()));
			holder.name_end.setText(order_info.location.name_end);
			// holder.name_end.setText(order_info.location.name_end.substring(
			// order_info.location.name_end.indexOf("市"),
			// order_info.location.name_end.length()));
			holder.serviceStatus.setText("距离"+LocationManager.getLocation(order_info.location.lat,order_info.location.lon));
			if (order_info.offer_price != null) {
				holder.price.setText(Utils
						.formatBalance(order_info.offer_price) + "元");
			}
			if (order_info.created_at != null) {
				holder.time.setText(TimeUtil.timeAgo(order_info.created_at));
			}
		}

		return null;
	}

	@Override
	public View createCellView() {
		return mInflater.inflate(R.layout.e0_published_orders_driver, null);
	}
}
